/**
 * Created by YMP on 2019/10/8.
 */
import Taro, { Component } from '@tarojs/taro'
import { View, Button } from '@tarojs/components'
import { login } from '@service/api/test'
import NavBar from '@components/common/XtNavBar'
import './index.scss'

export default class Index extends Component {
  state = {
    user: {}
  }

  componentWillMount() {}

  async componentDidMount() {
    let data = await login()

    if (data) {
      this.setState({
        user: data
      })
    }
  }

  componentWillUnmount() {}

  componentDidShow() {}

  componentDidHide() {}
  clickTest() {
    Taro.navigateTo({
      url: '/pages/demo/index'
    })
  }
  getUserInfo(res) {
    console.log(res, 'userinfo')
  }
  render() {
    const { user } = this.state
    return (
      <View className='index'>
        <NavBar custom-class='header' title='首页'></NavBar>
        <View onClick={this.clickTest} style={{ height: '50px', textAlign: 'center' }}>
          {' '}
          测试页面
        </View>
        <Button open-type='getUserInfo' onGetUserInfo={this.getUserInfo.bind(this)}>
          授权
        </Button>
        <View>{user.username}</View>
        <View>{user.userId}</View>
      </View>
    )
  }
}
